package TestSystemIO;

import java.io.*;

import TestSystemClient.Client;

public class OutputThread extends Thread {
	private BufferedWriter output;
	Object lockObj;
	
	public OutputThread (BufferedWriter output, Object lockObj, String name) {
		super(name);
		this.output = output;
		this.lockObj = lockObj;
	}

	public void run() {
		while(!Thread.currentThread().isInterrupted()) {
			synchronized(lockObj) {
				try {
					lockObj.wait();
					output.write(Client.messageToServer);
					System.out.print("Client sent to Server: " + Client.messageToServer);
					output.flush();
					Client.messageToServer = null;
				} catch (InterruptedException e) {
					Thread.currentThread().interrupt();
				} catch (IOException e) {
					Thread.currentThread().interrupt();
				}
			}
		}
	}
}